package com.example.tilas1.mapper.Sql;

import com.example.tilas1.pojo.Dept;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.ObjectUtils;

public class DeptMapperProvider {

    static final String TABLE_NAME = "dept";



    public String insertDept(Dept dept) {
        SQL sql = new SQL().INSERT_INTO(TABLE_NAME);
        if (!ObjectUtils.isEmpty(dept.getName())) {
            sql.INTO_COLUMNS("name");
            sql.INTO_VALUES("#{name}");
        }
        if (!ObjectUtils.isEmpty(dept.getCreateTime())) {
            sql.INTO_COLUMNS("create_time");
            sql.INTO_VALUES("#{createTime}");
        }
        if (!ObjectUtils.isEmpty(dept.getUpdateTime())) {
            sql.INTO_COLUMNS("update_time");
            sql.INTO_VALUES("#{updateTime}");
        }
        return sql.toString();
    }
  public String delete(Integer id){
      return new SQL().DELETE_FROM(TABLE_NAME).WHERE("id = #{id}").toString();
    }

    public String select(){
      return new SQL().SELECT("*").FROM(TABLE_NAME).toString();
    }

}
